package com.wwj.springboot.controller;

import com.wwj.springboot.entity.User;
import com.wwj.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;


/**
 * @author wwj
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public String login(String username, String password, HttpSession session){

        User user = userService.login(username,password);
        if (user!=null) {
            session.setAttribute("user",user);
            return "redirect:/product/selectAllProduct";
        }else{
            return "redirect:/login.jsp";
        }
    }
}
